﻿using System;
using System.Collections.Generic;

namespace Dxr.Police.Common
{
    public class AutoMapperInitializeWorker : Zongsoft.Services.WorkerBase
    {
        private List<IAutoMapperElement> _mappers;

        public AutoMapperInitializeWorker() : base()
        {
            _mappers = new List<IAutoMapperElement>();
        }

        public List<IAutoMapperElement> Mappers
        {
            get
            {
                return _mappers;
            }
        }

        protected override void OnStart(string[] args)
        {
            var config = new AutoMapper.Configuration.MapperConfigurationExpression();

            if (_mappers.Count > 0)
                _mappers.ForEach(p =>
                {
                    foreach (var item in p.CreateMapper())
                    {
                        config.CreateMap(item[0], item[1]);
                    }
                });

            AutoMapper.Mapper.Initialize(config);
        }

        protected override void OnStop(string[] args)
        {
        }
    }
}
